package cn.xfdzx.android.apps.shop.adapter.remake;

import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.List;

import cn.xfdzx.android.apps.shop.R;
import cn.xfdzx.android.apps.shop.activity.ShopActivity;
import cn.xfdzx.android.apps.shop.activity.XFDShopDetailsActivity;
import cn.xfdzx.android.apps.shop.adapter.remake.OrderMyRemake_Market_InnerAdapter;
import cn.xfdzx.android.apps.shop.bean.MyRemakeListMarketBean;
import cn.xfdzx.android.apps.shop.presenter.OrderRemakePresenter;
import cn.xfdzx.android.apps.shop.util.EmptyUtil;
import cn.xfdzx.android.apps.shop.util.ImageGlideUtil;
import cn.xfdzx.android.apps.shop.widget.CornerImageView;

/**
 * Creator: zf.
 * Date: 2020/9/15.
 * Description:订单评价商品列表适配器.-批发我的评价列表
 */
public class OrderMyRemake_MarketAdapter extends BaseQuickAdapter<MyRemakeListMarketBean.DataBean, BaseViewHolder>  {
    private OnItemOnClickListener onItemOnClickListener;
    private List<MyRemakeListMarketBean.DataBean> dataBeans;//拆分合并后的店铺数组
    private OrderMyRemake_Market_InnerAdapter innerAdapter;
    private OrderRemakePresenter mPresenter;
    public OrderMyRemake_MarketAdapter(@Nullable List<MyRemakeListMarketBean.DataBean> data, OrderRemakePresenter mPresenter) {
        super(R.layout.item_myremake_market, data);
        this.mPresenter = mPresenter;
    }

    @Override
    public void setData(int index, @NonNull MyRemakeListMarketBean.DataBean data) {
        super.setData(index, data);
    }

    @Override
    protected void convert(final BaseViewHolder viewHolder, final MyRemakeListMarketBean.DataBean date) {
        RelativeLayout rl_shoptitle = viewHolder.getView(R.id.rl_shoptitle);
        CornerImageView img_shophead = viewHolder.getView(R.id.img_shophead);
        img_shophead.setType(CornerImageView.TYPE_ROUND);

        RecyclerView recycler_remake = viewHolder.getView(R.id.recycler_remake);
        recycler_remake.setLayoutManager(new LinearLayoutManager(mContext));
        if (EmptyUtil.isNotEmpty(date.getReply())){
            innerAdapter = new OrderMyRemake_Market_InnerAdapter(date.getReply(),mPresenter);
            recycler_remake.setAdapter(innerAdapter);
        }

        ImageGlideUtil.loadImage(mContext,img_shophead,date.getStore_logo());

        viewHolder.setText(R.id.tv_shopname,date.getStore_name());

        rl_shoptitle.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(mContext, XFDShopDetailsActivity.class);
                intent.putExtra("shop_id",date.getStore_id());

                mContext.startActivity(intent);
            }
        });
    }

    private void setDrawableLeft(TextView tv_cai,Drawable drawable) {
        drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
        tv_cai.setCompoundDrawables(drawable, null, null, null);
    }

    public void clearDatas(){
        mData.clear();
        notifyDataSetChanged();
    }
    public void refreshDatas(List<MyRemakeListMarketBean.DataBean> list){
        super.replaceData(list);
    }

    public void setItemDeleteClickListener(OnItemOnClickListener listener){
        this.onItemOnClickListener = listener;
    }

    public interface OnItemOnClickListener {
        void onItemOnClick(int position, MyRemakeListMarketBean.DataBean date);
    }

}
